<?php
// Google Maps Mod
// by
// TLM <mindless@mindlesstux.com>

function template_map() {
	global $context, $modSettings, $scripturl;

    if ($modSettings['googleMapsEnable']) {
        echo '
    <table width="100%"><tr>
        <td class="windowbg2" colspan="2" valign="middle" align="center">
            <div id="map" style="width: 700px; height: 500px"></div>
            <div id="message"><a href="', $scripturl, '?action=profile;sa=forumProfile">Click hear to go place your pin if you have not already.</a></div>
            <script src="http://maps.google.com/maps?file=api&v=1&key=' . $modSettings['googleMapsKey'] . '" type="text/javascript"></script>
            <script type="text/javascript" language="JavaScript" src="', $scripturl, '?action=membermap;sa=.js"></script>
        </td>
    </tr></table>';
    }
}


/*
//The Old template thing that works
function template_map()
{
	global $context, $modSettings;

    if ($modSettings['googleMapsEnable']) {
        echo '
    <table width="100%"><tr>
        <td class="windowbg" colspan="2" valign="middle" align="center">
            <script src="http://maps.google.com/maps?file=api&v=1&key=' . $modSettings['googleMapsKey'] . '" type="text/javascript"></script>
            <div id="map" style="width: 700px; height: 500px"></div>

            <script type="text/javascript"> //<![CDATA[
    // Creates a marker whose info window displays the given number
    function createMarker(point, number, html, icon) {
        var marker = new GMarker(point, icon);

        // Show this markers index in the info window when it is clicked
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
        });

        return marker;
    }

    function LoadMap() {
        // Center the map on Palo Alto
        var map = new GMap(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.centerAndZoom(new GPoint(0, 0), 16);';
        foreach ($context['membermap'] as $marker) {
            if (isset($marker['latitude']) && isset($marker['longitude'])&& ($marker['latitude'] != '') && ($marker['longitude'] != '')) {
               $bubble ="'<div style=\"width: 13em; style: font-size: small\" align=\"left\">User: " . $marker['memberName'] . "<br />";
                if ($marker['location'] != '')
                    $bubble = $bubble . "Location: " . $marker['location'] . "<br />";
                if (($marker['websiteUrl'] != '') && ($marker['websiteTitle'] != ''))
                    $bubble = $bubble . "Website: <a href=\"". $marker['websiteUrl'] . "\">" . $marker['websiteTitle'] . "</a><br />";
                if ($marker['AIM'] != '')
                    $bubble = $bubble . "AIM: ". $marker['AIM'] . "<br />";
                if ($marker['ICQ'] != '')
                    $bubble = $bubble . "ICQ: ". $marker['ICQ'] . "<br />";
                if ($marker['MSN'] != '')
                    $bubble = $bubble . "MSN: ". $marker['MSN'] . "<br />";
                if ($marker['YIM'] != '')
                    $bubble = $bubble . "YIM: ". $marker['YIM'] . "<br />";
                    $bubble = $bubble . "</div>';";

                echo "
                    var html = $bubble";
                echo '
                    var point = new GPoint(' . $marker['latitude'] . ', ' . $marker['longitude'] . ');';
                echo '  var icon = new GIcon();';
                if ($modSettings['googleMapsPinGender']) {
                    if ($marker['gender'] == 0)
                    echo '
                    icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
                    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";';
                    elseif ($marker['gender'] == 1)
                    echo '
                    icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
                    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";';
                    elseif ($marker['gender'] == 2)
                    echo '
                    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
                    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";';
                } else {
                    echo '
                    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
                    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";';
                }
                    echo '
                    icon.iconSize = new GSize(12, 20);
                    icon.shadowSize = new GSize(22, 20);
                    icon.iconAnchor = new GPoint(6, 20);
                    icon.infoWindowAnchor = new GPoint(5, 1);';

                echo '
                    var marker = new createMarker(point, ' . $marker['ID_MEMBER'] . ', html, icon);';
                echo '
                    map.addOverlay(marker);';

            }
        }
        echo '
    }
    window.onload=LoadMap;
            //]]> </script>
        </td>
    </tr></table>';
    }
} */

?>
